/*Source

Problem Id:2701  User Id:Latex 
Memory:92K  Time:0MS
Language:G++  Result:Accepted

Source 
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

typedef struct
{
	int node;
	double dian[22][2];
}Tarea;

Tarea area[22], path;
double mind, maxd;

int n;
double ans;

double getheight(double xx1, double yy1, double xx2, double yy2, double xx0, double yy0)
{
	double h2, d1, d2, maxn, tmp, length;
	h2 = ((( (xx2-xx1)*(yy0-yy1) - (xx0-xx1)*(yy2-yy1)) * ( (xx2-xx1)*(yy0-yy1) - (xx0-xx1)*(yy2-yy1))))
		 / ( (xx2-xx1)*(xx2-xx1)+(yy2-yy1)*(yy2-yy1) );
	d1 = (xx0-xx1)*(xx0-xx1) + (yy0-yy1)*(yy0-yy1);
	d2 = (xx0-xx2)*(xx0-xx2) + (yy0-yy2)*(yy0-yy2);
	maxn = d1>d2? d1:d2;
	tmp = maxn - h2;
	length = (xx1-xx2)*(xx1-xx2) + (yy1-yy2)*(yy1-yy2);
	if (tmp > length) 
	{
		h2 = d1>d2? d2:d1;
	}
	return sqrt(h2);
	
}




double count(double tx1, double ty1, double tx2, double ty2)
{
	double minv, tmp;
	int i, j;
	minv = 2e20;
	for (i=1; i<=n; ++i)
	{
		for (j=1; j<=area[i].node; ++j)
		{
			tmp = getheight(tx1, ty1, tx2, ty2, area[i].dian[j][0],area[i].dian[j][1]);
			if (minv > tmp) minv = tmp;
		}
		for (j=1; j<area[i].node; ++j)
		{
			tmp = getheight(area[i].dian[j][0],area[i].dian[j][1]
						   ,area[i].dian[j+1][0],area[i].dian[j+1][1]
						   ,tx1, ty1);
			if (minv > tmp) minv = tmp;
			tmp = getheight(area[i].dian[j][0],area[i].dian[j][1]
						   ,area[i].dian[j+1][0],area[i].dian[j+1][1]
						   ,tx2, ty2);
			if (minv > tmp) minv = tmp;
		}
		tmp = getheight(area[i].dian[1][0],area[i].dian[1][1]
					   ,area[i].dian[area[i].node][0],area[i].dian[area[i].node][1]
					   ,tx1, ty1);
		if (minv > tmp) minv = tmp;
		tmp = getheight(area[i].dian[1][0],area[i].dian[1][1]
					   ,area[i].dian[area[i].node][0],area[i].dian[area[i].node][1]
					   ,tx2, ty2);
		if (minv > tmp) minv = tmp;

	}
	return minv;
		
}


int main()
{
	int i, j;
	bool first;
	
//	freopen("h.in", "r", stdin);
	while (1)
	{
		scanf("%lf%lf%d", &mind, &maxd, &n);
		first = true;
		if (n==0) break;
		for (i=1; i<=n; ++i)
		{
			scanf("%d", &area[i].node);
			for (j=1; j<=area[i].node; ++j)
				scanf("%lf%lf", &area[i].dian[j][0], &area[i].dian[j][1]);
		}
		scanf("%d", &path.node);
		for (i=1; i<=path.node; ++i)
			scanf("%lf%lf", &path.dian[i][0], &path.dian[i][1]);
		
		for (i=1; i<path.node; ++i)
		{
			ans = count(path.dian[i][0], path.dian[i][1], path.dian[i+1][0], path.dian[i+1][1]);
			if (ans < mind) ans = 0;
			if (ans > maxd) ans = maxd;
			if (first) 
			{
				printf("%.0lf", ans);
				first = false;
			}
			else 
				printf(" %.0lf", ans);
			
		}
		printf("\n");
		
	}

	
	
	
	return 0;	
}


